package com.mlingdu.supercloudreader.view;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import java.util.List;

/**
 * 项目名：SuperCloudReader
 * 包名：com.mlingdu.supercloudreader.view
 * Created by daimaren on 2017/6/28.
 */

public class MyFragmentPageAdapter extends FragmentPagerAdapter{
	private List<?> mFragment;
	private List<String> mTitleList;
	public MyFragmentPageAdapter(FragmentManager fm , List<?> mFragment) {
		super(fm);
		this.mFragment = mFragment;
	}

	public MyFragmentPageAdapter(FragmentManager fm, List<?> mFragment,List<String> mTitleList) {
		super(fm);
		this.mFragment = mFragment;
		this.mTitleList = mTitleList;
	}

	@Override
	public Fragment getItem(int position) {
		return (Fragment) mFragment.get(position);
	}

	@Override
	public int getCount() {
		return mFragment.size();
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		super.destroyItem(container, position, object);
	}

	@Override
	public CharSequence getPageTitle(int position) {
		if (mTitleList != null){
			return mTitleList.get(position);
		}
		else {
			return "";
		}
	}
	public void changeFragmentList(List<?> fragment){
		this.mFragment.clear();
		this.mFragment = null;
		this.mFragment = fragment;
		notifyDataSetChanged();
	}
}
